package edu.gwu.computerarchitecture.operation.execute;

import edu.gwu.computerarchitecture.cpu.CPUUnits;
import edu.gwu.computerarchitecture.entity.Register;
import edu.gwu.computerarchitecture.entity.Register32Bits;
import edu.gwu.computerarchitecture.entity.WordType;
import edu.gwu.computerarchitecture.operation.Instruction;

/**
 * 
 * implement the execution of STFR instruction
 *
 * <p>detailed comment
 * @author Erzheng Dai 2013年12月07日
 * @see Execute
 * @since 1.0
 * @version 1.0
 */
public class ExecuteSTFR extends Execute
{
    public ExecuteSTFR(CPUUnits units, Instruction instr)
    {
        super(units, instr);
        // TODO Auto-generated constructor stub
    }
    /**
     * 
     * implement the STFR
     * 
     * @see edu.gwu.computerarchitecture.operation.execute.Execute#execute()
     */
    public void execute(){
        calculateEA();
        Register32Bits rsr1 = frfRegister(instruction.rsr1);   
        cpuunits.mdr.setRegister(new WordType(rsr1.getRegister() & 0x0000ffff)); //Lower Byte store in Lower Address
        cpuunits.memory.StoreMemory();

        cpuunits.mar.setRegister(new WordType(cpuunits.mar.getRegister().getWord()+1));

        cpuunits.mdr.setRegister(new WordType((rsr1.getRegister() & 0xffff0000)>>>16)); //Lower Byte store in Lower Address
        cpuunits.memory.StoreMemory();
    }
}